package com.shop.api;

import com.shop.po.R;
import com.shop.user.po.GoodsComment;
import com.shop.user.service.GoodsCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author banxia
 * @since 2023-04-18
 */
@RestController
@RequestMapping("/goodsComment")
@CrossOrigin
public class GoodsCommentController {


    @Autowired
    private GoodsCommentService goodsCommentService;


    //用户评论
    @PostMapping("/comment")
    public R comment(@RequestParam("rate")Long rate,
                     @RequestParam("goodsId")Long goodsId,
                     @RequestParam("comment")String comment){
        goodsCommentService.comment(rate,goodsId,comment);
        return R.ok("成功评论该商品");
    }

    //查看得分
    @GetMapping("/getRate/{goodsId}")
    public R getRate(@PathVariable("goodsId")Long goodsId){
        String rate=goodsCommentService.getRate(goodsId);
        return R.ok().data("rate",rate);
    }
    
    //查看评论
    @GetMapping("/getComment/{goodsId}")
    public R getComment(@PathVariable("goodsId")Long goodsId){
        List<GoodsComment> list=goodsCommentService.getComment(goodsId);
        return R.ok().data("list",list);
    }


}

